﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:Fluent="clr-namespace:Fluent"
                    mc:Ignorable="d">
    
    <!--Button in Spinner Control Style-->
    <ControlTemplate x:Key="SpinnerButtonControlTemplate"
                     TargetType="{x:Type RepeatButton}">
        <Border x:Name="border"
                BorderThickness="1"
                CornerRadius="2"
                Background="{DynamicResource TransparentBrush}"
                BorderBrush="{DynamicResource TransparentBrush}"
                Height="Auto"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch">
            <Border x:Name="border1"
                    Height="Auto"
                    BorderBrush="{DynamicResource TransparentBrush}"
                    BorderThickness="1"
                    CornerRadius="2"
                    Background="{DynamicResource TransparentBrush}">
                <Grid Height="Auto">
                    <Rectangle x:Name="rectangle"
                               StrokeThickness="0"
                               Visibility="Collapsed">
                        <Rectangle.Fill>
                            <RadialGradientBrush Center="0.503,1"
                                                 GradientOrigin="0.503,1"
                                                 RadiusY="0.202">
                                <GradientStop Color="#7FFFFFFF"
                                              Offset="0" />
                                <GradientStop Offset="1" />
                            </RadialGradientBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                    <ContentPresenter x:Name="contentPresenter"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center" />
                </Grid>
            </Border>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver"
                     Value="False" />
            <Trigger Property="IsPressed"
                     Value="True">
                <Setter Property="BorderBrush"
                        TargetName="border"
                        Value="{DynamicResource ButtonPressedOuterBorderBrush}" />
                <Setter Property="Background"
                        TargetName="border"
                        Value="{DynamicResource ButtonPressedOuterBackgroundBrush}" />
                <Setter Property="Background"
                        TargetName="border1"
                        Value="{DynamicResource ButtonPressedInnerBackgroundBrush}" />
                <Setter Property="BorderBrush"
                        TargetName="border1"
                        Value="{DynamicResource ButtonPressedInnerBorderBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="contentPresenter"
                        Value="0.5" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True" />
                    <Condition Property="IsPressed"
                               Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="BorderBrush"
                        TargetName="border1"
                        Value="{DynamicResource ButtonHoverInnerBorderBrush}" />
                <Setter Property="Background"
                        TargetName="border1"
                        Value="{DynamicResource ButtonHoverInnerBackgroundBrush}" />
                <Setter Property="Background"
                        TargetName="border"
                        Value="{DynamicResource ButtonHoverOuterBackgroundBrush}" />
                <Setter Property="BorderBrush"
                        TargetName="border"
                        Value="{DynamicResource ButtonHoverOuterBorderBrush}" />
                <Setter Property="Visibility"
                        TargetName="rectangle"
                        Value="Visible" />
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style x:Key="SpinnerButtonStyle"
           TargetType="{x:Type RepeatButton}">
        <Setter Property="Template"
                Value="{DynamicResource SpinnerButtonControlTemplate}" />
        <Setter Property="Foreground"
                Value="{DynamicResource DefaultFontBrush}" />
    </Style>


    <!--Spinner Style-->
    <Style x:Key="SpinnerStyle"
           TargetType="{x:Type Fluent:Spinner}">
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Foreground"
                Value="{DynamicResource DefaultFontBrush}" />
        <Setter Property="Focusable"
                Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Fluent:Spinner}">

                    <Grid Width="Auto"
                          Height="22"
                          Background="#00000000">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal"
                                    Grid.ColumnSpan="1"
                                    x:Name="stackPanel"
                                    HorizontalAlignment="Left"
                                    Margin="0,0,3,0">
                            <ContentPresenter x:Name="iconImage"
                                              Width="16"
                                              Height="16"
                                              VerticalAlignment="Center"
                                              Margin="4,0,0,0"
                                              Content="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:StaticConverters.ObjectToImageConverter}}" />
                            <TextBlock Text="{TemplateBinding Header}"
                                       TextWrapping="Wrap"
                                       VerticalAlignment="Center"
                                       Margin="5,0,4,0"
                                       x:Name="textBlock" />
                        </StackPanel>

                        <Border x:Name="border"
                                Height="22"
                                BorderThickness="1"
                                BorderBrush="{DynamicResource TextBoxBorderBrush}"
                                Background="{DynamicResource TextBoxBackgroundBrush}"
                                Grid.ColumnSpan="1"
                                Grid.Column="1"
                                Width="{TemplateBinding InputWidth}"
                                HorizontalAlignment="Right">
                            <Grid Grid.ColumnSpan="1"
                                  Grid.Column="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="17" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>

                                <TextBox x:Name="PART_TextBox"
                                         BorderThickness="0"
                                         Grid.RowSpan="2"
                                         Grid.Column="0"
                                         Background="{DynamicResource TextBoxBackgroundBrush}"
                                         Foreground="{TemplateBinding Foreground}"
                                         Padding="2,0,2,0"
                                         Margin="0" />
                                <Path Visibility="Collapsed"
                                      HorizontalAlignment="Left"
                                      Margin="0,-1,0,-1"
                                      x:Name="path"
                                      Width="1"
                                      Fill="#FF000000"
                                      Stretch="Fill"
                                      Stroke="{DynamicResource TextBoxHoverBorderBrush}"
                                      StrokeThickness="1"
                                      Grid.Column="1"
                                      Grid.RowSpan="2"
                                      Data="M0,0L0,1" />
                                <Path HorizontalAlignment="Left"
                                      Margin="0,0,-1,0"
                                      Width="Auto"
                                      Fill="#FF000000"
                                      Stretch="Fill"
                                      Stroke="{DynamicResource TextBoxHoverBorderBrush}"
                                      StrokeThickness="1"
                                      Data="M0,0L1,0"
                                      Visibility="Collapsed"
                                      x:Name="path1"
                                      VerticalAlignment="Bottom"
                                      Height="1"
                                      Grid.Column="1"
                                      Grid.RowSpan="1" />
                                <RepeatButton x:Name="PART_ButtonUp"
                                              Grid.Column="1"
                                              Grid.Row="0"
                                              Style="{DynamicResource SpinnerButtonStyle}"
                                              RenderTransformOrigin="0,0.5"
                                              HorizontalAlignment="Stretch">
                                    <Path Width="5"
                                          Height="3"
                                          Fill="#FF000000"
                                          Stretch="Fill"
                                          Stroke="#FF000000"
                                          Data="M0,0L1,-1 2,0"
                                          HorizontalAlignment="Center"
                                          StrokeThickness="0"
                                          VerticalAlignment="Center"
                                          Margin="1,2,0,1"
                                          RenderOptions.EdgeMode="Aliased" />
                                </RepeatButton>
                                <RepeatButton x:Name="PART_ButtonDown"
                                              Grid.Column="1"
                                              Grid.Row="1"
                                              Style="{DynamicResource SpinnerButtonStyle}">
                                    <Path Width="5"
                                          Height="3"
                                          Fill="#FF000000"
                                          Stretch="Fill"
                                          Stroke="#FF000000"
                                          Data="M0,0L1,1 2,0"
                                          StrokeThickness="0"
                                          HorizontalAlignment="Center"
                                          Margin="1,-1,0,0"
                                          VerticalAlignment="Center"
                                          RenderOptions.EdgeMode="Aliased" />
                                </RepeatButton>
                            </Grid>
                        </Border>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="Icon"
                                 Value="{x:Null}">
                            <Setter Property="Visibility"
                                    TargetName="iconImage"
                                    Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="InputWidth"
                                 Value="NaN">
                            <Setter Property="HorizontalAlignment"
                                    TargetName="border"
                                    Value="Stretch" />
                        </Trigger>
                        <Trigger Property="IsEnabled"
                                 Value="False">
                            <Setter Property="IsEnabled"
                                    TargetName="PART_TextBox"
                                    Value="False" />
                            <Setter Property="Background"
                                    TargetName="border"
                                    Value="{DynamicResource TextBoxDisabledBackgroundBrush}" />
                            <Setter Property="BorderBrush"
                                    TargetName="border"
                                    Value="{DynamicResource TextBoxDisabledBorderBrush}" />
                            <Setter Property="Background"
                                    TargetName="PART_TextBox"
                                    Value="{DynamicResource TextBoxDisabledBackgroundBrush}" />

                            <Setter Property="Opacity"
                                    TargetName="iconImage"
                                    Value="0.5" />
                            <Setter Property="Opacity"
                                    TargetName="textBlock"
                                    Value="0.5" />
                            <Setter Property="Effect"
                                    TargetName="iconImage">
                                <Setter.Value>
                                    <Fluent:GrayscaleEffect />
                                </Setter.Value>
                            </Setter>
                        </Trigger>

                        <Trigger Property="Size"
                                 Value="Middle">
                            <Setter Property="Visibility"
                                    TargetName="textBlock"
                                    Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Size"
                                 Value="Small">
                            <Setter Property="Visibility"
                                    TargetName="stackPanel"
                                    Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter Property="Visibility"
                                    TargetName="path"
                                    Value="Visible" />
                            <Setter Property="Visibility"
                                    TargetName="path1"
                                    Value="Visible" />
                            <Setter Property="BorderBrush"
                                    TargetName="border"
                                    Value="{DynamicResource TextBoxHoverBorderBrush}" />
                            <Setter Property="Background"
                                    TargetName="border"
                                    Value="{DynamicResource TextBoxHoverBackgroundBrush}" />
                            <Setter Property="Background"
                                    TargetName="PART_TextBox"
                                    Value="{DynamicResource TextBoxHoverBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>